package com.link2room.jetfire.controller.manager;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.util.DateUtil;
import com.link2room.common.util.LogUtil;
import com.link2room.jetfire.dto.param.manager.ReservationManagerParamDto;
import com.link2room.jetfire.facade.IReservationFacadeService;
import com.link2room.jetfire.dto.param.base.ReservationParamDto;
import com.link2room.jetfire.dto.result.base.ReservationDto;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.link2room.jetfire.constant.PermissionConstant.*;

/**
 * Created by sss on 2016/9/20.
 */
@Api(tags = "订单管理")
@RestController
@RequestMapping("/manager/Reservations")
public class ReservationManagerController {
    @Resource
    private IReservationFacadeService reservationFacadeService;

    @ApiOperation(value = "按条件获取订单详情",response = ReservationDto.class)
    @RequestMapping(method = RequestMethod.GET)
    @L2RPermissionResources(value = reservations, name = "订单列表")
    public BaseResultDto reservations(
            @RequestParam(value = "lhotelCode" ,required = false) String lhotelCode,
            @RequestParam(value = "l2rNo" ,required = false) String l2rNo,
            @RequestParam(value = "terminalNo" ,required = false) String terminalNo,
            @RequestParam(value = "crsNo" ,required = false) String crsNo,
            @RequestParam(value = "resSta" ,required = false) String resSta,
            @RequestParam(value = "confirmSta" ,required = false) String confirmSta,
            @RequestParam(value = "createTime" ,required = false) String createTime,
            @RequestParam(value = "arr" ,required = false) String arr,
            @RequestParam(value = "dep" ,required = false) String dep,
            @RequestParam(value = "sortBy" ,required = false) String sortBy,
            @RequestParam(value = "order" ,required = false) String order
    )throws Exception{
        ReservationManagerParamDto reservationParamDto=new ReservationManagerParamDto();
        reservationParamDto.setLhotelCode(lhotelCode);
        reservationParamDto.setL2rNo(l2rNo);
        reservationParamDto.setCrsNo(crsNo);
        reservationParamDto.setTerminalNo(terminalNo);
        reservationParamDto.setResSta(resSta);
        reservationParamDto.setConfirmSta(confirmSta);
        reservationParamDto.setCreateTime(DateUtil.parseDateUtcFormat(createTime));
        reservationParamDto.setArr(DateUtil.parseDateUtcFormat(arr));
        reservationParamDto.setDep(DateUtil.parseDateUtcFormat(dep));
        reservationParamDto.setSortBy(sortBy);
        reservationParamDto.setOrder(order);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(reservationFacadeService.listReservations(reservationParamDto));
        return l2rRs;
    }

    @ApiOperation(value = "根据ID获取订单详情",response = ReservationDto.class)
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @L2RPermissionResources(value = reservation, name = "订单详情")
    public BaseResultDto reservation(
            @PathVariable Long id
    )throws Exception{
        ReservationParamDto reservationParamDto=new ReservationParamDto();
        reservationParamDto.setId(id);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(reservationFacadeService.getReservation(reservationParamDto));
        return l2rRs;
    }
}
